#import "NSDictionary+Extension.h"

@implementation NSDictionary (Extension)

+ (id)dictionaryWithString:(NSString *)string
{
    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
    
    return [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
}

- (NSString *)string:(NSString *)string
{
    id value = self[string];
    
    if ([value isEqual:[NSNull null]]) return @"";
    
    return value;
}

- (NSNumber *)intValue:(NSString *)string
{
    return [NSNumber numberWithUnsignedInt:[[self string:string] intValue]];
}

- (NSNumber *)floatValue:(NSString *)string
{
    return [NSNumber numberWithDouble:[[self string:string] doubleValue]];
}

- (BOOL)isEqualDictionary:(NSDictionary *)dictionary
{
	for (NSString *key in self.allKeys)
	{
		if (dictionary[key] && ![dictionary[key] isEqualToString:self[key]]) return NO;
	}
	
	return YES;
}

@end
